<?php

namespace app\api\logic;

use app\common\model\AnswerQuestion;

class ErrorQuestion
{
    /**
     * 查询列表
     * @param $param
     * @return array
     */
    public function getProfession($param): array
    {
        //提取参数
        $userId = $param['userId'];
        $courseId = $param['course_id'] ?? 0;

        //查询条件
        $where = [
            'a.user_id' => $userId,
            'a.status' => 2
        ];
        if ($courseId > 0) {
            $where['b.id'] = $courseId;
        }

        //查询数据
        $field = 'count(*) count,a.course_id,b.code,b.name';
        $list = app(AnswerQuestion::class)
            ->alias('a')
            ->leftJoin('course b', 'a.course_id = b.id')
            ->field($field)
            ->where($where)
            ->group('course_id')
            ->select();
        $list = $list ? $list->toArray() : [];
        return $list;
    }

}